﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SolveLoops.ViewModels.CApSolveLoopsViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.SolveLoops.ViewModels;

public class CApSolveLoopsViewModel : TxViewModelBase
{
  private ITxKinematicsModellable _device;
  private TxKinematicLink _selectedLink;
  private IList _selectedJoints;

  public ObservableCollection<TxObjectComboBoxItem> Links { get; set; } = new ObservableCollection<TxObjectComboBoxItem>();

  public TxKinematicLink SelectedLink
  {
    get => this._selectedLink;
    set
    {
      this.Set<TxKinematicLink>(ref this._selectedLink, value, new string[1]
      {
        nameof (SelectedLink)
      });
    }
  }

  public ObservableCollection<DataGridItem> Joints { get; set; } = new ObservableCollection<DataGridItem>();

  public IList SelectedJoints
  {
    get => this._selectedJoints;
    set
    {
      this.Set<IList>(ref this._selectedJoints, value, new string[1]
      {
        nameof (SelectedJoints)
      });
    }
  }

  public CApSolveLoopsViewModel()
  {
    TxObjectList items = TxApplication.ActiveSelection.GetItems();
    if (((Collection<ITxObject>) items).Count == 1 && ((Collection<ITxObject>) items)[0] is ITxKinematicsModellable)
      this._device = ((Collection<ITxObject>) items)[0] as ITxKinematicsModellable;
    this.InitLinks();
    this.InitJoints();
  }

  private void InitJoints()
  {
    TxIconManager.the().GetObjectIcon((ITxObject) ((Collection<TxJoint>) this._device.Joints)[0]);
    TxObjectList<TxJoint> joints = this._device.Joints;
    List<DataGridItem> dataGridItemList1;
    if (joints == null)
    {
      dataGridItemList1 = (List<DataGridItem>) null;
    }
    else
    {
      IEnumerable<DataGridItem> source = ((IEnumerable<TxJoint>) joints).Select<TxJoint, DataGridItem>((Func<TxJoint, DataGridItem>) (item => new DataGridItem(TxIconManager.the().GetObjectImageSource((ITxObject) item), item.Name, item)));
      dataGridItemList1 = source != null ? source.ToList<DataGridItem>() : (List<DataGridItem>) null;
    }
    List<DataGridItem> dataGridItemList2 = dataGridItemList1;
    if (dataGridItemList2 == null || dataGridItemList2.Count <= 0)
      return;
    foreach (DataGridItem dataGridItem in dataGridItemList2)
      this.Joints.Add(dataGridItem);
  }

  private void InitLinks()
  {
    foreach (ITxObject link in (Collection<ITxObject>) this._device.Links)
      this.Links.Add(new TxObjectComboBoxItem(link.Name, link));
  }
}
